package com.hbx.residential_service.dao;

import com.hbx.residential_service.domain.CarSite;
import com.hbx.residential_service.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CarSiteDao {
    @Select("select * from carsites")
    @Results({
            @Result(id=true,property = "csId",column = "csId"),
            @Result(property = "csNum",column = "csNum"),
            @Result(property = "csStatus",column = "csStatus"),
            @Result(property = "csCarNum",column = "csCarNum"),
            @Result(property = "user",column = "csUserId",javaType = User.class,one = @One(select = "com.hbx.residential_service.dao.UserDao.findById"))
    })
    List<CarSite> findAll(int page, int size);

    @Insert("insert into carsites(csNum,csStatus,csCarNum,csUserId) values(#{csNum},#{csStatus},#{csCarNum},#{user.userid})")
    void addCarSite(CarSite carSite);

    @Delete("delete from carsites where csId=#{csId}")
    void deleteCarSite(int csId);

    @Select("select * from carsites where csId=#{csId}")
    @Results({
            @Result(id=true,property = "csId",column = "csId"),
            @Result(property = "csNum",column = "csNum"),
            @Result(property = "csStatus",column = "csStatus"),
            @Result(property = "csCarNum",column = "csCarNum"),
            @Result(property = "user",column = "csUserId",javaType = User.class,one = @One(select = "com.hbx.residential_service.dao.UserDao.findById"))
    })
    CarSite findUpdCSById(int csId);

    @Update("update carsites set csNum=#{csNum},csStatus=#{csStatus},csCarNum=#{csCarNum},csUserId=#{user.userid} where csId=#{csId}")
    void UpdateCSById(CarSite carSite);

    @Select("select * from carsites where csUserId in (select userid from owners where username like #{content})")
    @Results({
            @Result(id=true,property = "csId",column = "csId"),
            @Result(property = "csNum",column = "csNum"),
            @Result(property = "csStatus",column = "csStatus"),
            @Result(property = "csCarNum",column = "csCarNum"),
            @Result(property = "user",column = "csUserId",javaType = User.class,one = @One(select = "com.hbx.residential_service.dao.UserDao.findById"))
    })
    List<CarSite> fsByUsername(@Param("content") String content,@Param("page") int page, @Param("size") int size);
}
